class BookProgress {
  int? id;
  final int bookId;
  final String title;
  int lastReadPage;
  double fontSize;

  BookProgress({
    this.id,
    required this.bookId,
    required this.title,
    required this.lastReadPage,
    required this.fontSize,
  });


  // 本地书籍应该带地址！
  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'book_id': bookId,
      'title': title,
      'last_read_page': lastReadPage,
      'font_size': fontSize,
    };
  }

  factory BookProgress.fromMap(Map<String, dynamic> map) {
    return BookProgress(
      id: map['id'],
      bookId: map['book_id'],
      title: map['title'],
      lastReadPage: map['last_read_page'],
      fontSize: map['font_size'],
    );
  }

  // 添加更多信息到 toString 方法
  @override
  String toString() =>
      'BookProgress(id: $id, bookId: $bookId, title: $title, lastReadPage: $lastReadPage)';

  // 添加 copyWith 方法，便于更新
  BookProgress copyWith({
    int? id,
    int? bookId,
    String? title,
    int? lastReadPage,
    double? fontSize
  }) {
    return BookProgress(
      id: id ?? this.id,
      bookId: bookId ?? this.bookId,
      title: title ?? this.title,
      lastReadPage: lastReadPage ?? this.lastReadPage,
      fontSize: fontSize ?? this.fontSize,
    );
  }

  // 重写 == 和 hashCode 方法
  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
          other is BookProgress &&
              runtimeType == other.runtimeType &&
              id == other.id &&
              bookId == other.bookId &&
              title == other.title &&
              lastReadPage == other.lastReadPage;

  @override
  int get hashCode =>
      id.hashCode ^ bookId.hashCode ^ title.hashCode ^ lastReadPage.hashCode;
}